<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/excite-bike/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css" />
<link href="css/table.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.22.custom.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/widgets.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
		$('#square').css("visibility", "hidden");
		$('input[id$=Date]').datepicker({
			dateFormat : 'yy-mm-dd'
		});
		$("button").button();
		$("#loginUser")[0].value = $.cookie("userID");
		
		$("#dialog-delTC").css("visibility", "hidden");	//刪除測試案例
	});

	function but(bType,uID,tcID,tcName,CreatedDateTime,Creator) {
		if (bType=='r') {
			return '<button type=\"button\" onclick=\"location.href=\'ReplicateTC.html?uID='+uID+'&tcID='+tcID+'&tcName='+tcName+'\'\">複製</button>';
		} else if (bType=='u'){
			return '<button type=\"button\" onclick=\"location.href=\'UpdateTC.html?uID='+uID+'&tcID='+tcID+'&tcName='+tcName+'\'\">修改</button>';
		} else if (bType=='d'){
			return '<button type=\"button\" onclick=\"location.href=\'MappingTC.html?tcID='+tcID+'\'\">編輯版次對應</button>';
		} else if (bType=='k'){
			return '<button type=\"button\" onclick=\"click_deleteTC(\''+tcID+'\')\">刪除</button>';
		}
	}
	
	function click_deleteTC(tcid) {
		$("#dialog-delTC").prop("title","刪除測試案例");
		$('#q_tcID2')[0].value = tcid;
		$('#delTC_tcid').html(tcid);
		$("#dialog-delTC").css("visibility", "visible");
		$("#dialog-delTC").dialog({
			resizable : true,
			width : 300,
			height : 300,
			modal : true,
			buttons : {
				"確定" : function() {
					$.ajax({
						type : 'post',
						url : 'DeleteTC',
						data : $('#q_form_mapping').serializeArray(),
						dataType : 'TEXT',
						success : function(queryResult) {
							$('#tr_'+tcid).remove();
							refreshUI('resultTable_b',1);
							alert(queryResult);
						}
					});
					$(this).dialog("close");
				},"關閉" : function() {
					$(this).dialog("close");
				}
			}
		});
	}
	
	function click_submit(){
		var isNotBlank = 0;
		var str = "";
		$.each($('.require_from_group'), function(i, val) {
			str = str + val['value']; // val是一個物件，若要取得物件中的值，需指定要屬性的名稱，也可以寫成val.value
			if (!($.trim(val['value']) == '')) {
				isNotBlank = 1;
			}
		});
		$('#resultTable_b').html('');
		if (isNotBlank == 0) {
			$('#q_message').html('請至少輸入一個查詢欄位');
		} else { //表示有輸入，要開始查詢
			$('#q_message').html('');	//效果不太一樣，頂著先
			x = $('#q_form').serializeArray();
			$.ajax({
				type : 'post',
				url : 'QueryTC',
				data : x,
				dataType : 'JSON',
				success : function(queryResult) {
					 if (queryResult.strSQL[0]["result"] == 'No Result') {
						$('#q_message').html("沒找到!!");
					} else {
						$.each(	queryResult.sqlData,function(i,res) {
							var ind= i+1;
							var bgcolor=getbgColor(ind);
							$('#ReaultNum').html('共有'+ind+'筆資料');
							$('#resultTable_b').append(
								'<tr id=\'tr_'+res.tcID+'\' bgcolor=\''+bgcolor+'\'><td>'
								+ ind
								+ '</td><td>'
								+ but('k',res.uID,res.tcID,res.tcName,res.CreatedDateTime,res.Creator)
								+ but('r',res.uID,res.tcID,res.tcName,res.CreatedDateTime,res.Creator)
								+ but('u',res.uID,res.tcID,res.tcName,res.CreatedDateTime,res.Creator)
								+ but('d',res.uID,res.tcID,res.tcName,res.CreatedDateTime,res.Creator)
								+ '</td><td>'
								+ res.tcID
								+ '</td><td>'
								+ res.tcName
								+ '</td><td>'
								+ res.CreatedDateTime
								+ '</td><td>'
								+ res.Creator
								+ '</td></tr>');
							});
								
							$('#square').css("visibility", "visible");
						}
					}
				});
		}
	}
	
	function click_reset(){
		$.each($('.require_from_group'), function(i, val) { //將每個欄位都設為空字串
			val['value'] = '';
		});
		$('#q_message').html('');	//效果不太一樣，頂著先
		$('#square').css("visibility", "hidden");
	}
</script>



<title>測試案例維護</title>
</head>
<body>

<form id='q_form' method="post">
		<table>
			<tr>
				<th colspan="2" valign="middle" scope="col">請輸入查詢條件</th>
			</tr>
			<tr>
				<th width="130" valign="middle" scope="col">
					<div align="right">測試案例ID：</div>
				</th>
				<td scope="col"><div align="left">
						<input type="text" name="q_tcID" id='q_tcID'
							class='require_from_group' />
					</div></td>
			</tr>
			<tr>
				<th valign="middle"><div align="right">
						測試案例名稱：</div></th>
				<td bgcolor="#CCCCCC"><input type="text" name='q_tcName'
					id='q_tcName' class='require_from_group' /></td>
			</tr>
			<tr>
				<th valign="middle"><div align="right">
						繼承自：</div></th>
				<td><input type='text' id='q_parentTCID' name='q_parentTCID'
					class='require_from_group' /></td>
			</tr>
			<tr>
				<th valign="middle"><div align="right">
						建立者：</div></th>
				<td bgcolor="#CCCCCC"><input type="text" name='q_creator'
					id='q_creator' class='require_from_group' /></td>
			</tr>
			<tr>
				<th rowspan="2" valign="middle"><div
						align="right">建立日期：</div>
					<div align="right"></div></th>
				<td width="208"><label> 起：<input type="text"
						name="q_fromDate" id="q_fromDate" class='require_from_group' />
				</label></td>
			</tr>
			<tr>
				<td width="223">迄：<input type="text" name="q_toDate"
					id="q_toDate" class='require_from_group' /></td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td>
					<button type="button" id='clickS' onClick="click_submit()">提交 </button>
					<button type="button" id='clickReset' onClick="click_reset()">重設</button>
				</td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td id='q_message' class='require_from_group'>&nbsp;</td>
			</tr>
		</table>
	</form>


	<div id='square'>
		
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<h2 id='ReaultNum'></h2>
		<hr />

		<table id='resultTable'>
			<thead id='resultTable_h'>
				<tr>
					<th>#</th>
					<th>&nbsp;</th>
					<th>測試案例ID</th>
					<th>案例名稱</th>
					<th>建立日期</th>
					<th>建立者</th>
				</tr>
			</thead>
			
			<tbody id='resultTable_b'>
			</tbody>
		</table>
	</div>
	
	<form id='q_form_mapping' method="post">
		<input type="hidden" id='q_tcID2' name='q_tcID' value='' />
		<input type="hidden" id="loginUser" name="loginUser" />					<!-- 目前登入的使用者 -->
	</form>
	
	<div id="dialog-delTC">
	<table>
		<tbody id="ConfirmDelTC">
		<tr><th>確定刪除</th></tr>
		<tr><td id="delTC_tcid"></td></tr>
		
		</tbody>
	</table>
	</div>
	
	
</body>
</html>